import javax.sound.midi.Soundbank;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 19182
 * Date: 2025-09-10
 * Time: 19:45
 */
public class demo4 {
}
class Solution {
    public int bitSum(int n){
        int t = n;
        int sum = 0;
        while(t != 0){
            sum += (t % 10) * (t % 10);
            t /= 10;
        }
        return sum;
    }
    public boolean isHappy(int n) {
        int slow = n;
        int fast = bitSum(n);
        while(slow != fast){
            slow = bitSum(slow);
            fast = bitSum(bitSum(fast));
        }
        return slow == 1;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        boolean ret = solution.isHappy(19);
    }
}